//
//  DepoistTypeListVC.swift
//  d11
//
//  Created by peale on 2018/10/19.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit

class DepoistTypeListVC: BXBaseVC,UITableViewDelegate,UITableViewDataSource,EndEidtDelegate {
    let  reuseIdentifierID : NSString = "DepoistTypeListHeadCell"
    let  reuseIdentifierID2 : NSString = "DepoistTypeListItemCell"
    let  reuseIdentifierID3 : NSString = "DepoistTypeListSubItemCell"
    let  reuseIdentifierID4 : NSString = "HomeCopyrightCell"
    var dataList:[String:[[String:Any]]]? = [:]
    var dataArray:[[String:Any]]?
    var bankDetails:String?
    var atmBank:[[String:Any]]?   //atm数据列表 字典形式
    var atmDict:[String:Any]?   //atm显示条
    var limitMin:String = "0" //第三方的最低取款限额
    var limitMax:String = "0" //第三方的最高取款限额
    var count:Int = 0
    var pendingDeposit:Bool? //atm
    var isInit:Bool = true
    
    var bankDict:[String:Any]?   //bank显示条
    var money : String = ""//搜索金额
    var listArray :[[String:Any]]?
    var tempList : [[String:Any]]?
    lazy var tableView:UITableView = {
        let table = UITableView(frame:CGRect(x: 0, y: 0, width: self.view.width, height:kScreenHeight), style:UITableView.Style.plain)
        table.dataSource = self
        table.delegate = self
        //table.layoutMargins = UIEdgeInsets.zero
        table.separatorStyle = .none
        table.backgroundColor  = UIColor.white
        table.showsVerticalScrollIndicator = false
        table.tableFooterView = UIView.init()
        table.separatorStyle = .none
        table.autoresizingMask = [.flexibleWidth,.flexibleHeight]
        table.estimatedRowHeight = 0
        table.estimatedSectionHeaderHeight = 0
        table.estimatedSectionFooterHeight = 0
        
        table.mj_header = MJRefreshNormalHeader(refreshingBlock: {
            self.getDepositsList()
            
        })
        return table
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 设置导航栏默认返回按钮
        self.leftButtonActionWithImg("icon_default_back")
        self.navigationController?.navigationBar.shadowImage = UIImage()
        
        self.listArray = [[String:Any]]()
        self.tempList = [[String:Any]]()
        self.view.backgroundColor = UIColor.white
        self.view.addSubview(self.tableView)
        self.getDepositsList()
    }
    
    func getDepositsList() ->Void{
        self.showLoadHUD(title: "")
        NetWorkRequest(API.getDepositsList(url: "7d44e91"), completion: { (responseData,statusCode,strData) -> (Void) in
            self.dismissLoadHUD()
            DispatchQueue.main.async {
                self.listArray = [[String:Any]]()
                self.tempList = [[String:Any]]()
                //清除money和输入框
                self.money = ""
                let cell = self.tableView.cellForRow(at: .init(row: 0, section: 0)) as? DepoistTypeListHeadCell
                //清空金额输入框
                cell?.clearMoney()
                let  dataDict  = responseData["data"].dictionary
                let maindisplayordered =  dataDict?["maindisplayordered"]?.stringValue //总列表顺序字符串 - 存款通道排序
                let bqdisplayordered =  dataDict?["bqdisplayordered"]?.stringValue //bq列表顺序字符串 - 支付通道排序
                let fydisplayordered =  dataDict?["fydisplayordered"]?.stringValue //fy列表顺序字符串 - 支付通道排序
                let aadisplayordered =  dataDict?["aadisplayordered"]?.stringValue //aa列表顺序字符串 - 支付通道排序
                let gcdisplayordered = dataDict?["gcdisplayordered"]?.stringValue  //gc列表顺序字符串 - 支付通道排序
                let ltdisplayordered = dataDict?["ltdisplayordered"]?.stringValue  //lt列表顺序字符串 - 支付通道排序
                var mainTypeList : [String]? = maindisplayordered?.components(separatedBy: ",")  //分割总顺序数组 
                let bqTypeList = bqdisplayordered?.components(separatedBy: ",")  //分割bq顺序数组
                let fyTypeList = fydisplayordered?.components(separatedBy: ",")  //分割fy顺序数组
                let aaTypeList = aadisplayordered?.components(separatedBy: ",")  //分割aa顺序数组
                let gcTypeList = gcdisplayordered?.components(separatedBy: ",")  //分割gc顺序数组
                let ltTypeList = ltdisplayordered?.components(separatedBy: ",")  //分割lt顺序数组
                let depoistModelList = GlobalInfo.depoistModelList
                let bankList = GlobalInfo.bankList
                mainTypeList?.append("100")
                for i in 0 ..< (mainTypeList?.count ?? 0){
                    let itemString : String = mainTypeList?[i] ?? ""
                    //是否在game.json存在。 存在才显示
                    var isExist = false
                    for item in depoistModelList ?? [[String:Any]()]{
                        let optionId : String = item["optionid"] as! String
                        if(optionId==itemString){
                            isExist = true
                            break
                        }
                    }
                    if(itemString == "bq"){
                        
                    }
                    if(isExist){
                        var itemDict = [String:Any]()
                        //                    if itemString == "bq" || itemString == "fy" {
                        if itemString == "bq" || itemString == "fy" || itemString == "aa" || itemString == "gc" || itemString == "lt"{
                            let itemArray = dataDict?[itemString]?.arrayObject
                            if itemArray != nil && (itemArray?.count ?? 0) > 0{
                                if itemString == "bq"{
                                    itemDict[itemString] = self.connectedBQorFYData(isAA: false,itemArray: itemArray, typeList: bqTypeList, depoistModelList: depoistModelList)
                                }else if itemString == "fy"{
                                    itemDict[itemString] = self.connectedBQorFYData(isAA: false, itemArray: itemArray, typeList: fyTypeList, depoistModelList: depoistModelList)
                                    print("测试测试fy：\(itemDict)")
                                }
                                else if itemString == "aa"{
                                    itemDict[itemString] = self.connectedBQorFYData(isAA : true,itemArray: itemArray, typeList: aaTypeList, depoistModelList: depoistModelList)
                                    print("测试测试aa：\(itemDict)")
                                }else if itemString == "gc"{
                                    itemDict[itemString] = self.connectGcData(itemArray: itemArray, typeList: gcTypeList, depoistModelList: depoistModelList, bankList: bankList)
                                    print("测试测试gc：\(itemDict)")
                                }else if itemString == "lt"{
                                    itemDict[itemString] = self.connectGcData(itemArray: itemArray, typeList: ltTypeList, depoistModelList: depoistModelList, bankList: bankList)
                                    print("测试测试lt：\(itemDict)")
                                }
                                
                                for i2 in 0 ..< (depoistModelList?.count ?? 0){
                                    var item = depoistModelList?[i2] ?? [String:Any]()
                                    if (item["optionid"] as? String ?? "") == itemString {
                                        item["keyType"] = itemString
                                        itemDict["showInfo"] = item
                                        break
                                    }
                                }
                                self.listArray?.append(itemDict)
                            }
                        }
                        else if itemString == "1"{
                            let itemArray = dataDict?[itemString]?.arrayObject
                            itemDict[itemString] = self.connectYHData(itemArray: itemArray, bankList: bankList)
                            for i2 in 0 ..< (depoistModelList?.count ?? 0){
                                var item = depoistModelList?[i2] ?? [String:Any]()
                                if (item["optionid"] as? String ?? "") == itemString {
                                    item["keyType"] = itemString
                                    itemDict["showInfo"] = item
                                    break
                                }
                            }
                            self.listArray?.append(itemDict)
                            
                            print("测试测试：\(itemDict)")
                        }
                        else{
                            print("测试数据：\(dataDict?[itemString]?.dictionaryObject?.count)")
                            if dataDict?[itemString]?.dictionaryObject != nil && dataDict?[itemString]?.dictionaryObject?.count ?? 0 > 0{
                                itemDict[itemString] = dataDict?[itemString]?.dictionaryObject
                                for i2 in 0 ..< (depoistModelList?.count ?? 0){
                                    var item = depoistModelList?[i2] ?? [String:Any]()
                                    if (item["optionid"] as? String ?? "") == itemString {
                                        item["keyType"] = itemString
                                        itemDict["showInfo"] = item
                                        break
                                    }
                                }
                                self.listArray?.append(itemDict)
                            }
                        }
                    }
                }
                for temp in self.listArray!{
                    self.tempList?.append(temp)
                }
                //           print("数据\(self.listArray)")
                self.tableView.reloadData()
                self.tableView.mj_header?.endRefreshing()
                
            }
        }, failed: { (faildInfo,reCode,msg) -> (Void) in
            self.dismissLoadHUD()
            DispatchQueue.main.async {
                self.tableView.mj_header?.endRefreshing()
                if reCode == "21002"{
                    UIHelper.displayLoginExpireTip(self)
                }else{
                    UIHelper.alertSimpleMessage(about: "\(faildInfo)", withDescription: "", in: self)
                }
            }
        }) { () -> (Void) in
            self.dismissLoadHUD()
            DispatchQueue.main.async {
                UIHelper.alertSimpleMessage(about: "网络请求异常!", withDescription: "", in: self)
                self.tableView.mj_header?.endRefreshing()
            }
        }
    }
    //处理银行数据
    func connectYHData(itemArray:[Any]?,bankList:[[String : Any]]?) -> Array<[String:Any]>{
        var newArray = Array<[String:Any]>()
        var newItemDict = [String:Any]()
        for j1 in 0 ..< (itemArray?.count ?? 0){
            let itemDict = itemArray?[j1] as? [String:Any] ?? [:]
            print("\(j1)---\(itemDict)")
            let typeStr = "\(j1)"
            for j2 in 0 ..< (bankList?.count ?? 0){
                var item = bankList?[j2] ?? [String:Any]()
                if (item["logo"] as? String ?? "") == (itemDict["banklogo"]  as? String ?? "-1") {
                    item["keyType"] = typeStr
                    newItemDict["showInfo"] = item
                    break
                }
            }
            newItemDict[typeStr] = itemDict
            newArray.append(newItemDict)
        }
        return newArray
    }
    func connectGcData(itemArray:[Any]?,typeList:[String]?,depoistModelList:[[String : Any]]?,bankList:[[String : Any]]?) -> Array<[String:Any]>{
        print("=====\(typeList)==\(itemArray)")
        var newArray = Array<[String:Any]>()
        for j in 0 ..< (typeList?.count ?? 0){
            let typeStr = typeList?[j] ?? ""
            var newItemDict = [String:Any]()
            for j1 in 0 ..< (itemArray?.count ?? 0){
                let itemDict = itemArray?[j1] as? [String:Any] ?? [:]
                let optionId = itemDict["optionid"] as? String ?? ""
//                print("=====gc==\(typeStr)===\(optionId)")
                if(optionId == "1" && typeStr == "1"){
                    for j2 in 0 ..< (bankList?.count ?? 0){
                        var item = bankList?[j2] ?? [String:Any]()
                        if (item["logo"] as? String ?? "") == (itemDict["banklogo"]  as? String ?? "-1") {
                            item["keyType"] = typeStr
                            newItemDict["showInfo"] = item
                            newItemDict[typeStr] = itemDict
                            newArray.append(newItemDict)
                            break
                        }
                    }
                }else if(optionId == typeStr){
                    for j2 in 0 ..< (depoistModelList?.count ?? 0){
                        var item = depoistModelList?[j2] ?? [String:Any]()
                         if (item["optionid"] as? String ?? "") == (itemDict["optionid"]  as? String ?? "-1") {
                            print("\(item["optionid"] as? String ?? ""))====\(itemDict["optionid"]  as? String ?? "-1")")
                            item["keyType"] = typeStr
                            newItemDict["showInfo"] = item
                            newItemDict[typeStr] = itemDict
                            newArray.append(newItemDict)
                            break
                        }
                    }
                }

            }
        }
        return newArray
    }
    //处理bq/fy数据关联显示数据
    func connectedBQorFYData(isAA : Bool,itemArray:[Any]?,typeList:[String]?,depoistModelList:[[String : Any]]?) -> Array<[String:Any]>{
        var newArray = Array<[String:Any]>()
        for j in 0 ..< (typeList?.count ?? 0){
            let typeStr = typeList?[j] ?? ""
            var newItemDict = [String:Any]()
            for j1 in 0 ..< (itemArray?.count ?? 0){
                let itemDict = itemArray?[j1] as? [String:Any] ?? [:]
                if typeStr == (itemDict["optionid"] as? String ?? "-1"){
                    for j2 in 0 ..< (depoistModelList?.count ?? 0){
                        var item = depoistModelList?[j2] ?? [String:Any]()
                        if(isAA){
                            if (item["optionid"] as? String ?? "") == (itemDict["optionid"]  as? String ?? "-1") {
                                item["keyType"] = typeStr
                                newItemDict["showInfo"] = item
                                break
                            }
                        }else{
                            if (item["optionid"] as? String ?? "") == (itemDict["optionid"]  as? String ?? "-1") {
                                item["keyType"] = typeStr
                                newItemDict["showInfo"] = item
                                break
                            }
                        }
                    }
                    newItemDict[typeStr] = itemDict
                    newArray.append(newItemDict)
                    break
                }
            }
        }
        return newArray
    }
    
    //获取第三方和BQ支付列表
    func getPayList() -> Void {
        
        NetWorkRequest(API.getDepositsPayList(url: "98efaec", ccToken: API.getCcToken(), vcToken: API.getVcToken()), completion: { (responseData,statusCode,strData) -> (Void) in
            DispatchQueue.main.async {
                let dataDict = responseData["data"].dictionaryObject
                let bankList:[String] = dataDict?["bankOption"] as! [String]
                let limitDict =  dataDict?["limit"] as? [String:Any] ?? [:]
                
                self.limitMin = limitDict["min"] as? String ?? "0"
                self.limitMax = limitDict["max"] as? String ?? "0"
                self.bankDetails = dataDict?["bankDetails"] as? String ?? ""
                for  (_,item) in bankList.enumerated(){
                    let array : Array = item.components(separatedBy: "|")
                    if array.count>=3{
                        let logoStr = array[0]
                        var tempArr = [[String:Any]]()
                        if logoStr == "logo-WEBPAY"{  //网银跳转
                            tempArr.append(["logo":array[0],"type":array[1],"sort":array[2]])   //type 6或者23是BQ
                            self.dataList!["0"] = tempArr
                        }else{
                            for (_,item2) in bankList.enumerated() {
                                let item2Arr : Array = item2.components(separatedBy: "|")
                                if item2Arr.count >= 3{
                                    if array[1] == item2Arr[1] && item2Arr[0] != "logo-WEBPAY"{
                                        tempArr.append(["logo":item2Arr[0],"type":item2Arr[1],"sort":item2Arr[2]])   //type 6或者23是BQ
                                    }
                                }
                                self.dataList![array[1]] = tempArr
                            }
                        }
                    }
                    
                }
                
                let paymenList  =  GlobalInfo.paymentlist
                if paymenList != nil {
                    self.dataArray  = []
                    for (_,item) in (paymenList?.enumerated())!{
                        let typeStr = item["type"] as! String
                        if typeStr == "1" && item["specialtag"] as? String ?? "1" == "2"{ //网银跳转
                            if  self.dataList!["0"] != nil {
                                print("\(item)")
                                self.dataArray?.append(item)
                            }
                        }else{
                            if  self.dataList![typeStr] != nil {
                                print("\(item)")
                                self.dataArray?.append(item)
                            }
                        }
                    }
                }
                //                self.pendingDeposit = dataDict!["pendingDeposit"] as? Bool ?? false
                //                if self.pendingDeposit == true{ //显示审核页面
                //                    self.dismissLoadHUD()
                //                    let vc =  DepoistCheckingVC()
                //                    self.navigationController?.pushViewController(vc, animated: true)
                //                }
                //               self.getATMList(isShowpd: self.pendingDeposit!)
                //              self.getATMList()
                self.dataArray = self.dataArray?.sorted(by: {(item1, item2) -> Bool in
                    let a = item1["orderpd"] as? String ?? "0"
                    let b = item2["orderpd"] as? String ?? "0"
                    //        print("\(item1)---\(item2)")
                    return Int(a)! < Int(b)!
                })
                self.tableView.reloadData()
            }
        }, failed: { (faildInfo,reCode,msg) -> (Void) in
            DispatchQueue.main.async {
                self.dismissLoadHUD()
                if reCode == "21002"{
                    UIHelper.displayLoginExpireTip(self)
                }else{
                    UIHelper.alertSimpleMessage(about: "\(faildInfo)", withDescription: "", in: self)
                }
                self.tableView.mj_header?.endRefreshing()
            }
        }) { () -> (Void) in
            DispatchQueue.main.async {
                self.dismissLoadHUD()
                UIHelper.alertSimpleMessage(about: "网络请求异常!", withDescription: "", in: self)
                self.tableView.mj_header?.endRefreshing()
            }
            
        }
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if (self.listArray?.count ?? 0) == 0{
            return 2
        }else{
            return (self.listArray?.count ?? 0) + 1
        }
        
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.row == 0 {
            return 250
        }else{
            if (self.listArray?.count ?? 0) == 0 || indexPath.row >= (self.listArray?.count ?? 0){
                return 487
            }else{
                return 60
            }
        }
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView.init()
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        print("======\(indexPath.row)===\(indexPath.section)")
        if indexPath.row == 0{
            var cell :DepoistTypeListHeadCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID as String) as? DepoistTypeListHeadCell
            if cell == nil {
                cell =  DepoistTypeListHeadCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID as String)
                cell?.bgItemBtn?.addTarget(self, action: #selector(self.actionToItemPage),for: .touchUpInside)
            }
            if self.listArray == nil || self.listArray?.count == 0{
                cell?.setData(dict: nil)
            }else{
                cell?.setData(dict: self.listArray?[indexPath.row])
            }
            cell?.delegate = self
            return cell!
        }else{
            if (self.listArray?.count ?? 0) == 0 || indexPath.row >= (self.listArray?.count ?? 0) {
                var cell :HomeCopyrightCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID4 as String) as? HomeCopyrightCell
                if cell == nil {
                    cell =  HomeCopyrightCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID4 as String)
                }
                return cell!
            }else{
                var cell :DepoistTypeListItemCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID2 as String) as? DepoistTypeListItemCell
                if cell == nil {
                    cell =  DepoistTypeListItemCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID2 as String)
                }
                cell?.setData(dict: self.listArray?[indexPath.row])
                return cell!
            }
        }
    }
  
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 0{
            //     self.selectItem(indexPath: indexPath)
        }else{
            if (self.listArray?.count ?? 0) == 0 || indexPath.row >= (self.listArray?.count ?? 0) {
                //底部版权图片
            }else{
                self.selectItem(indexPath: indexPath)
            }
        }
    }
    
    func selectItem(indexPath: IndexPath) ->Void{
        
        let depoistModel = self.listArray?[indexPath.row]
        print("选中======\(depoistModel)")
        let infoDict = depoistModel?["showInfo"] as? [String:Any] ?? [String:Any]()
        let optionid : String = infoDict["optionid"] as? String ?? ""
        if optionid == "atm"{
            self.getAtmPendingTransaction(dict: depoistModel ?? [String:Any]())
        }else if optionid == "bq" || optionid == "fy" ||  optionid == "1" || optionid == "aa" || optionid == "gc" || optionid == "lt"{//bq /fy
            //        }else if optionid == "bq" || optionid == "fy" ||  optionid == "1" {//bq /fy 1
            let vc =  DepoistVC()
            vc.moneyCount = self.money
            if depoistModel != nil{
                let tempArray = depoistModel?[optionid] as? [[String : Any]] ?? [[String:Any]]()//获取到数组
                if tempArray.count >= 1{
                    let tempModel = tempArray[0]
                    let tempDict = tempModel["showInfo"] as? [String:Any] ?? [String:Any]()
                    let keyType = tempDict["keyType"] as? String ?? ""
                    let bankLogo = tempDict["banklogo"] as? String ?? ""
                    var optionidNew : String = tempDict["optionid"] as? String ?? ""
                    let temp = tempModel[optionidNew] as? [String:Any] ?? [String:Any]()
                    let bqoption : String = temp["bqoption"] as? String ?? ""
                    var isInput = false
                    
                    vc.pageType = 1
                    vc.isDepoistInput = false
                    if optionid == "bq" || optionid == "aa" || optionid == "fy" || optionid == "gc" || optionid == "lt"{
                        isInput = true
                        if(optionid == "gc" || optionid == "lt"){
                            vc.pageType = 1
                            vc.isDepoistInputInfo = true
                        }else{
                            vc.pageType = 2
                            vc.isDepoistInputInfo = true
                        }
                        
                        if(optionid == "aa"){
                            vc.isDepoistAA = true
                        }
                        if(optionid == "bq"){
                            vc.isDepoistBQ = true
                        }
                    }else if optionid == "1"{
                        vc.isBank = true
                    }
                    if (keyType == "6" && bankLogo == "logo-PAYCARD" && isInput == true)
                        || (bqoption == "2" && bankLogo != "logo-ZFB" &&  isInput == true)
                        || (bqoption == "3" &&  isInput == true){
                        vc.pageType = 2
                        vc.isDepoistInput = true
                    }else if (bqoption == "2" && bankLogo == "logo-ZFB" &&  isInput == true){
                        vc.pageType = 2
                        vc.isOneUserName = true
                        vc.isDepoistInput = true
                    }
                    //                    if (optionid == "bq" && keyType == "6" && bankLogo == "logo-PAYCARD") ||
                    //                        (optionid == "aa" && keyType == "6" && bankLogo == "logo-PAYCARD"){
                    //                        vc.pageType = 2
                    //                        vc.isDepoistInput = true
                    //                    }else{
                    //                        vc.pageType = 1
                    //                        vc.isDepoistInput = false
                    //                    }
                }else{
                    vc.pageType = 0
                }
                for temp in tempArray{
                    print("二级支付方式======\(temp)")
                }
                vc.depoistList = tempArray
            }
            self.navigationController?.pushViewController(vc, animated: true)
        }else{//三方
            let vc =  DepoistVC()
             vc.moneyCount = self.money
            if depoistModel != nil{
                vc.pageType = 1
                vc.depoistList = [depoistModel] as? [[String : Any]]
            }
            
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
    func getAtmPendingTransaction(dict:[String:Any]) -> Void {
        self.showLoadHUD(title:"")
        NetWorkRequest(API.atmPendingTransaction(url: "6307c74"), completion: { (responseData,statusCode,strData) -> (Void) in
            DispatchQueue.main.async {
                self.dismissLoadHUD()
                let dataDict = responseData["data"].dictionary
                let pendingAtm = dataDict?["pendingATM"]?.string ?? "false"
                
                if pendingAtm == "true" {//玩家有未完成提交的人工智能存款
                    let cardinfoDict = dataDict?["cardinfo"]?.dictionary
                    let vc = DepoistInfoVC()
                    vc.pendingAtm = pendingAtm
                    vc.bcid = cardinfoDict?["bcid"]?.intValue
                    let money = cardinfoDict?["amount"]?.double ?? 0
                    vc.moneyCount =  money.truncatingRemainder(dividingBy: 1) == 0 ? String(format:"%.0f", money):String(money)
                    vc.realName = cardinfoDict?["owner"]?.string
                    vc.bankNo = cardinfoDict?["card"]?.string
                    vc.bankName = cardinfoDict?["name"]?.string
                    vc.address = cardinfoDict?["addr"]?.string
                    vc.bankCss = cardinfoDict?["css"]?.string
                    if vc.bankCss != nil{
                        let totalBankList = GlobalInfo.bankList
                        if totalBankList != nil {
                            for ( _,dict) in (totalBankList?.enumerated())! {
                                if vc.bankCss == dict["logo"] as? String ?? ""{
                                    vc.bankicon =  dict["image"] as? String ?? ""
                                    break
                                }
                            }
                        }
                    }
                    self.navigationController?.pushViewController(vc, animated: true)
                }else{
                    let vc =  DepoistATMVC()
                    vc.depoistATMDict = dict
                    vc.pendingAtm = pendingAtm
                    vc.moneyCount = self.money
                    self.navigationController?.pushViewController(vc, animated: true)
                }
                
                
            }
        }, failed: { (faildInfo,reCode,msg) -> (Void) in
            DispatchQueue.main.async {
                self.dismissLoadHUD()
                if reCode == "21002"{
                    UIHelper.displayLoginExpireTip(self)
                }else{
                    UIHelper.alertSimpleMessage(about: "ATM:\(faildInfo)", withDescription: "", in: self)
                }
            }
        }) { () -> (Void) in
            DispatchQueue.main.async {
                self.dismissLoadHUD()
                UIHelper.alertSimpleMessage(about: "获取数据异常!", withDescription: "", in: self)
            }
        }
    }
    
    @objc func actionToItemPage() -> Void {
        self.selectItem(indexPath: IndexPath.init(row: 0, section: 0))
    }
    
    func getMoney(money : String) {
        self.money = money
        self.listArray = tempList
        if(money != ""){
            self.listArray = listArray?.filter{ (data) -> Bool in
                let showInfo = data["showInfo"] as! [String:Any]
                let optionid = showInfo["optionid"] as! String
                let optionData = data[optionid] as? [String:Any] ?? [String:Any]()
                var rangeLimit = optionData["rangeLimit"] as? String
                if(rangeLimit == nil){
                    let tempOptionData = data[optionid] as? [[String:Any]] ?? [[String:Any]]()
                    let temp = tempOptionData[0] as? [String:Any] ?? [String:Any]()
                    for (key, value) in temp {
                        if(key != "showInfo"){
                            let values = temp[key] as? [String:Any] ?? [String:Any]()
                            rangeLimit = values["rangeLimit"] as? String ?? ""
                            break
                        }
                    }
                }
                
                let ranges = rangeLimit?.components(separatedBy: ",")
                if(ranges != nil && ranges!.count>0){
                    let min = (ranges![0] as NSString).doubleValue
                    let max = (ranges![1] as NSString).doubleValue
                    let moneyStr = (money as NSString).doubleValue
                    if(moneyStr>=min&&moneyStr<=max){
                        return true
                    }
                }
                return false
            }
        }
         self.tableView.reloadData()
    }
}
